<%@include file="/WEB-INF/jsp/taglib.jsp" %>
<c:import url="/WEB-INF/jsp/frontend/script.jsp"/>

<script src="https://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

    <div id="allcontent" style="height:423px; background:#FFFFFF; margin-top:10px; padding:0px 5px; " align="center">
        <div id="catogory">
            <b>
                <span style="color:Red">管理操作人员</span>
            </b>
        </div>
    <div id="list">
          <table style="padding-top:0px" width="960" border="0" align="center">
               <tbody>
                    <tr>
                        <td style="padding-right:20px" align="left">
                            <form action="/maintain/userManage" id="searchForm" name="userSearch">
                                <input id="email_fragment" name="email_fragment" value="" width="198" type="text">
                                <input id="userSearchBtn" value="用户邮箱查询" onclick="submit()" type="submit">
                            </form>
                        </td>
                        <td style="padding-right:20px" align="right">
                            <input value="新增记录" onclick="modifyRecord(0);" type="button">
                        </td>
                    </tr>
                </tbody>
          </table>

        <table width="940" border="0">
            <tbody>
            <tr>
                <td>
                    <b>用户邮箱</b>
                </td>
                <td>
                    <b>用户昵称</b>
                </td>
                <td>
                    <b>权限类别</b>
                </td>
                <td>
                    <b>操作</b>
                </td>
            </tr>
            <tr id="newRecord" style="display:none">
            <c:forEach items="${userPage.list}" var="user" varStatus="idx" >
            <tr>
                <td>
                    <input id="user_email${idx.index}"  style="width:150px" width="198" type="text" value="${user.userEmail}">

                    <input id="peopleid${idx.index}" value="23" type="hidden">
                </td>

                <td>
                    <input id="user_name${idx.index}"  style="width:150px" width="198" type="text" value="${user.userName}">
                </td>

                <td>
                    <input id="classification${idx.index}"  style="width:150px" type="text" value="${user.userAuthority} + index-${idx.index}">
                </td>

                <td>
                    <input id="modifybtn${idx.index}" value="修改记录" onclick="showUserRecord(${idx.index})" type="button">
                    <%--<input id="deletebtn${idx.index}" value="删除记录" onclick="javascript:deleteRecord(1);" type="button" onclick="showUserRecord(${idx.index});">--%>
                </td>
            </tr>
            </c:forEach>
            <tr>

            </tr>
            </tbody>
        </table>
            <div id="databuffer" style="display:none">
                <div id="signupbox" style="display:none; align:center">
                </div>
            </div>
            </div>
        页次：${userPage.currentPage}/${userPage.totalPage}&nbsp;每页${userPage.pageSize}&nbsp;总数${userPage.totalRecord}&nbsp;&nbsp;&nbsp;&nbsp;
        <a href="javaScript:gotoPage(1, '${emailFragment}')">首页</a>
        <c:choose>
            <c:when test="${userPage.currentPage>1}">
                <a href="javaScript:gotoPage('${userPage.currentPage-1}','${emailFragment}')">上一页</a>
            </c:when>
            <c:otherwise>
                <a href="#">上一页</a>
            </c:otherwise>
        </c:choose>

        <c:choose>
            <c:when test="${userPage.currentPage<userPage.totalPage}">
                <a href="javaScript:gotoPage('${userPage.currentPage+1}','${emailFragment}')">下一页</a>
            </c:when>
            <c:otherwise>
                <a href="#">下一页</a>
            </c:otherwise>
        </c:choose>
        <a href="javaScript:gotoPage('${userPage.totalPage}', '${emailFragment}')">尾页</a>
        <select id="userPageSelect" width="50" style="width: 40px" onchange="jumpPage('${emailFragment}');">
            <c:forEach var="i" begin="1" end="${userPage.totalPage}">

                <c:choose>
                    <c:when test="${userPage.currentPage== i}">
                        <option selected="selected">${i}</option>
                    </c:when>
                    <c:otherwise>
                        <option>${i}</option>
                    </c:otherwise>
                </c:choose>
            </c:forEach>
        </select>
        </div>
<%--
&nbsp;&nbsp;
<c:forEach var="i" begin="1" end="${page.totalPage}">
   <a href="<c:url value='/classify.htm?c=${page.list[0].classifyid}&p=${i}'/>">${i}</a>
</c:forEach>
--%>

<br/><br/><br/><br/>
<%--maintain/userModify--%>

<div id="userModifyModal" class="modal hide fade in" >
    <div class="modal-dialog" >
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3>修改用户信息</h3>
            </div>
            <form name="userModify" id="userForm">
                <div class="modal-body">
                    <input id="userEmail" disabled="disabled" type="text" value="用户邮箱"/>
                    <input type="text" id="email"  name="email_content"/>
                    <br/>
                    <input  disabled="disabled" type="text" value="用户昵称"/>
                    <input type="text" id="name" name="name_content"/>
                    <br/>
                    <input id="userAuth" disabled="disabled" type="text" value="用户权限"/>
                    <select name="classification" style="width:105px; height: 20px; line-height: 0px; font-size:12px;border: 1px solid #CCCCCC; border-radius: 0px 0px 0px 0px; margin-bottom: 0px;padding: 0px 0px;">
                        <option value="0">注册未激活</option>
                        <option value="1">注册已激活</option>
                        <option value="2">冻结</option>
                        <option value="3">管理员</option>
                        <option value="-1">删除</option>
                    </select>
                </div>
                <div class="modal-footer">
                    <button id="userModifyBtn" type="submit" class="btn btn-success btn-lg btn-block" >提交</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    var userUrl = "<spring:url value="/maintain/userModify" />";
    var userForm = $("#userForm");
    var userModifyBtn = $("#userModifyBtn");

    userModifyBtn.click(function () {
        $.ajax({
            type: "POST",
            cache: false,
            async: false,
            url: userUrl,
            data: userForm.serialize(),
            dataType: "json",
            success: function (data) {
                if (data.success) {
                    alert(data.msg);
                    location.reload(true);
                } else {
                    alert(data.msg);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("修改失败");
                alert(XMLHttpRequest.status);
                alert(XMLHttpRequest.readyState);
                alert(textStatus);
            }
        });
        return false;
    });


    function gotoPage(pageNum, emailFragment){
//        console.log();

        var targetURL="<spring:url value='/maintain/userManage?p='/>" + pageNum + "&email_fragment=" + emailFragment;

        document.location.href=targetURL;
    }

    function jumpPage(emailFragment){
        var idx = document.getElementById("userPageSelect").selectedIndex+1;
        var targetURL="<spring:url value='/maintain/userManage?p='/>" + idx + "&email_fragment=" + emailFragment;
        document.getElementById("userPageSelect")[idx-1].selected=true;
        document.location.href=targetURL;

    }
</script>
